SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ArchiveEMail]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[ArchiveEMail]
GO

/***************************************************************************
* Name:			ArchiveEMail
****************************************************************************/
CREATE PROCEDURE [dbo].[ArchiveEMail] (
	@to VARCHAR(150) ,
	@from VARCHAR(150) ,
	@subject VARCHAR (256) ,
	@bodyText VARCHAR(4000),
	@smtpServer VARCHAR(128) 
)

AS

BEGIN
	


	INSERT INTO EMailArchive( 
						[To] ,
						[From] ,
						Subject ,
						BodyText ,
						SMTPServer ,
						DateSent	
					)
					VALUES
					( 
						@to,
						@from,
						@subject,
						@bodyText,
						@smtpServer,
						GETDATE()
					)
		
		IF @@ERROR <> 0 GOTO ERROR_HANDLER
			

	ERROR_HANDLER:
		IF @@ERROR <> 0 
		BEGIN
			RAISERROR('Unable to Archive sent E-Mail', 16, 1)
			RETURN
		END
END

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

